<?php

    if(!@$_POST['akses'] == true) {
	   die('Akses langsung tidak diperbolehkan!');
	}
    
    include("dboper.php");
    $d_sistem = getConfig();
	$d_sesi	  = getAllSesi();
	$d_matkul = getAllMatkul();
	$d_kelas  = getAllKelas();
	$d_japrak = getOneJaprak($d_sistem['japrak']);
    if($d_sistem['jenisPolling'] == 'SINGLE'){
        $met1 = "selected";
    } else {
        $met2 = "selected";
    }    

    if($d_sistem['lihatHasil'] == 'PRIVATE'){
        $akse1 = "selected";
    } else {
        $akse2 = "selected";
    }   

    if($d_sistem['cekIP'] == 'YA'){
        $cekIP1 = "selected";
    } else {
        $cekIP2 = "selected";
    }    
	
	$hari_arr= array("Senin","Selasa","Rabu","Kamis","Jumat","Sabtu");
	  $idhari_arr= array("SN","SL","RB","KM","JM","SB");

?>
<h4>Ubah Konfigurasi</h4>
<form id="formEditConfig" method="POST">
	<table>
		<tr><td></td><td><input required="" type="hidden" value="true" name="akses"></td></tr>
        <input required="" type="hidden" value="DOUBLE" name="txtMetode">
        <input required="" type="hidden" value="PRIVATE" name="txtAkses">
        <input required="" type="hidden" value="YA" name="txtIP">
        <input required="" type="hidden" value="TIDAK" name="txtMAC">
		<tr><td colspan="2"><b>Evaluasi</b> </i></td></tr>
		<tr><td>Hari</td><td>
		<select required="" name="txtHari" style="width:100px" type="text">
              <option >pilih</option>
			  <?php
					for($i=0;$i<sizeof($hari_arr);$i++){
					$selected="";
					if($idhari_arr[$i]==$d_japrak['hari']){
						$selected="selected";
					}
				?>
				 <option <?php echo $selected; ?> value="<?php echo $idhari_arr[$i];?>" ><?php echo $hari_arr[$i]; ?></option>
				<?php
					}
				?>
            </select>
			</td></tr>
		<tr><td>Sesi</td><td>
		<select required="" name="txtSesi" style="width:130px" type="text">
              <option >pilih</option>
			  <?php for($i=0;$i<sizeof($d_sesi);$i++){ 
					$selected="";
					if($d_sesi[$i]['id_sesi']==$d_japrak['id_sesi']){
						$selected="selected";
					}
			  ?>
					
					<option <?php echo $selected; ?> value="<?php echo $d_sesi[$i]['id_sesi']?>" ><?php echo $d_sesi[$i]['jam_mulai']."-".$d_sesi[$i]['jam_selesai']?></option>
			  <?php } ?>
            </select>
			</td></tr>
		<tr><td>Kelas</td><td>
        <select required="" name="txtNamaKelas" style="width:100px" >
              <option value="" >pilih</option>
             <?php for($i=0;$i<sizeof($d_kelas);$i++){ 
					$selected="";
					if($d_kelas[$i]['id_kelas']==$d_japrak['id_kelas']){
						$selected="selected";
					}
			 ?>
					<option <?php echo $selected; ?> value="<?php echo $d_kelas[$i]['id_kelas'];?>" ><?php echo $d_kelas[$i]['nama_kelas'];?></option>
			  <?php } ?>
            </select>  	
			</td></tr>
		<tr><td>Matakuliah</td><td>
		<select required="" name="txtNamaMakul" style="width:200px" type="text">
              <option >pilih</option>
			   <?php for($i=0;$i<sizeof($d_matkul);$i++){ 
					$selected="";
					if($d_matkul[$i]['id_matkul']==$d_japrak['id_matkul']){
						$selected="selected";
					}
			   ?>
					<option <?php echo $selected ?> value="<?php echo $d_matkul[$i]['id_matkul'];?>" ><?php echo $d_matkul[$i]['jurusan']." - ".$d_matkul[$i]['nama_matkul'];?></option>
			  <?php } ?>
            </select>
			</td></tr>
		
		<tr><td colspan="2"><b>Pesan</b> </i></td></tr>
		<tr><td>Pesan Sistem</td><td><textarea type="text" name="txtPesanSistem"><?php echo $d_sistem['pesan'];?></textarea></td></tr>
		<tr><td>Pesan Depan</td><td><textarea type="file" name="txtPesanDepan"><?php echo $d_sistem['pesanDepan'];?></textarea></td></tr>
		<tr><td colspan="2"><b>Pengguna</b> </i></td></tr>
		<tr><td>Username</td><td><input required="" type="text" value="<?php echo $d_sistem['username'];?>" name="txtUsername"></td></tr>
		<tr><td>Password</td><td><input required="" type="text" value="<?php echo $d_sistem['password'];?>" name="txtPassword"></td></tr>
		<tr><td></td><td><input required="" type="submit" value="Simpan"></td></tr>
	</table>
</form>
<script type="text/javascript" >
	$("#formEditConfig").submit(function(e){	
		var a=$('#formEditConfig').serialize();
		$.ajax({
			type: "POST", 
			async: false, 
			url: 'proseditconfig.php',   
			data : a ,
			success: function(a){	
                alert('Data konfigurasi berhasil diperbarui.');
				$("#loading").hide();
				return false;
			},
			error: function(){
				var obj = jQuery.parseJSON(a);
				alert(obj+"error");	
				$("#loading").hide();
				return false;
			}
		}); 
	});
</script>
